
package podcastbyphone.server;

import java.util.Properties;
import java.util.StringTokenizer;

import twilio.client.urlconnection.TwilioClient;

// util
public class TwilioProperties
{
	static private String accountPhoneNumber;
	static private String accountSid;
	static private String authToken;
	
	static
	{
		try
		{
			java.util.Properties props = new Properties();
			
			props.load(TwilioProperties.class.getResourceAsStream("twilio.properties"));
			
			String phoneNumber = (String) props.get("account.phonenumber");

			StringBuffer temp = new StringBuffer();
			
			for (int i = 0; i < phoneNumber.length(); i++)
			{
				char c = phoneNumber.charAt(i);
				if (Character.isDigit(c))
				{
					temp.append(c);
				}
			}
			
			accountPhoneNumber = temp.toString();
			
			accountSid = (String) props.get("account.sid");
			authToken = (String) props.get("account.authtoken");
		}
		catch (Throwable t)
		{
			t.printStackTrace();
		}
	}
	
	static public TwilioClient createClient()
	{
		TwilioClient client = new TwilioClient(getAccountSid(), getTwilioAuthToken());
		
		return client;
	}
	
	static public String getAccountSid()
	{
		return accountSid;
	}
	
	static public String getAccountPhoneNumber()
	{
		return accountPhoneNumber;
	}
	
	static public String getTwilioAuthToken()
	{
		return authToken;
	}

}
